  
  <form action="#" method="post">  
        <h4>Tạo mới nhóm quyền</h4>

        <fieldset>
            <p>
                <label><?=t_lang('group_name')?></label>
                <input type="text" class="text-input small-input" id="group_name" />
            </p>
            <p>
                <label><?=t_lang('permission_view')?></label>
                <div style="overflow-y:scroll; width:250px; height:150px; border:1px solid #ccc; padding: 10px;">
                    <?php foreach($permissions as $per):?>
                        <input type="checkbox" class="per_view" name="permis_view[]" value="<?=$per;?>" <?php echo set_checkbox('permis_view[]', $per);?>> <?=ucfirst($per);?><br>
                    <?php endforeach;?>
                </div>
            </p>
            
            <p>
                <label><?=t_lang('permission_edit')?></label>
                <div style="overflow-y:scroll; width:250px; height:150px; border:1px solid #ccc; padding: 10px;">
                    <?php foreach($permissions as $per):?>
                        <input type="checkbox" class="per_edit" name="permis_edit_delete[]" value="<?=$per;?>" <?php echo set_checkbox('permis_edit_delete[]', $per);?>>&nbsp;<?=ucfirst($per);?><br>
                    <?php endforeach;?>
                </div>
            </p>
            
            <a class="button" href="javascript:void(0);" onClick="addGroup();"><?=t_lang('btn_save')?></a>
            <a class="button" onClick="jQuery(document).trigger('close.facebox')"><?=t_lang('btn_close')?></a>
        </fieldset>
  </form> 
  
<script>

   function addGroup()
   {
       var groupName = $('#group_name').val();
       
       var perView = $('input:checkbox:checked.per_view').map(function() {
            return this.value;
        }).get();
       
       var perEdit = $('input:checkbox:checked.per_edit').map(function() {
            return this.value;
        }).get();
       
       if(groupName == '')
       {
           alert('Please enter Group Name');
           $('#group_name').focus();
           return false;
       } else if(perView == '')
       {
           alert('Please choose a Permission View');
       } else if(perEdit == '')
       {
           alert('Please choose a Permission Edit');
       } else {
           $.ajax({
                type: "POST",
                dataType: "json",
                data: "groupName=" + groupName + "&perView=" + perView + "&perEdit=" + perEdit,
                url: '<?=$a_action_add_group?>',
                success: function(data)
                {
                    if(data)
                    {                
                        alert(data.message);
                        jQuery(document).trigger('close.facebox');
                        loadListGroup();
                    } else {
                        alert(data.message);
                    }
                }
            });
       }
   }

</script>
